<template>
  <view class="g-content">
    <uni-card
      class="card-course"
      :is-shadow="true"
      v-for="item in courseList"
      :title="item['课程名']"
      :extra="item['课时数']+''"
      @click="toSelectSign(item)"    
      :id="item['课程号']"
      note="点击发起签到"
    >
      <view><span>上课时间：</span>{{ item['上课时间'] }}</view>      
      <view><span>上课地点：</span>{{ item['上课地点'] }}</view>
      <view><span>教授专业：</span>{{ item['教授专业'] }}</view>
    </uni-card>
    <uni-card
      class="card-course"
      :is-shadow="true"
      v-for="item in labList"
      :extra="item['实验课节数']+''"
      :title="item['课程名']"
      :id="item['实验课编号']"
      thumbnail="../../../static/icon/exp.png"
      :note="item['上课地点']!=null ? null : '点击发起申请'"
    > 
      <view v-if="item['上课地点'] != null">
        <view><span>上课时间：</span>{{ item['上课时间'] }}</view>
        <view><span>上课地点：</span>{{ item['上课地点'] }}</view>
        <view><span>教授专业：</span>{{ item['教授专业'] }}</view>
      </view>
      <view v-else @click="toSelectLab(item)">
        <view><span>教授专业：</span>{{ item['教授专业'] }}</view>      
      </view>
    </uni-card>
    <uni-fab @fabClick="toCourse" vertical="top"></uni-fab>
    <div style="height: 120rpx;"></div>
    <hans-tabber :list="tab" class="g-tabbar" style="position:fixed;bottom:0;width:100%;left:0;right:0;" :current="0"></hans-tabber>
  </view>
</template>

<script>
  import Teacher from '../../../api/Teacher.js';
  export default {
    data(){
      return{
        uid: this.$store.state.token.id,
        courseList: [],
        labList: [],
        tab: [
          {
            "text":"学期课程",
            "pagePath":"curriculum",
            "iconPath":"../../../static/icon/task.png",
            "selectedIconPath":"../../../static/icon/task.png"
          },
          {
            "text":"申请记录",
            "pagePath":"apply",
            "iconPath":"../../../static/icon/task.png",
            "selectedIconPath":"../../../static/icon/task.png"
          }
        ]
      }
    },
    onInit() {
      this.uid = this.$store.state.token.id;
    },
    onLoad() {
      this._initCourseList();
      this._initLabList();
    },
    methods:{
      toCourse(){
        uni.navigateTo({
          url: 'adder'
        })
      },
      async _initCourseList(){
        this.Test.log('老师-学期课程',this.uid);
        const rm = (await Teacher.courses(this.uid));
        this.Test.log('老师-学期课程',rm);
        if(rm[1]['statusCode'] == '200'){
          if(rm[1].data == [] || rm[1].data == ''){
            this.Toast.show('无课程');
            this.courseList = [];
            return;
          }
          this.courseList = rm[1].data;
          //this.Toast.show('数据已加载');
        }
      },
      async _initLabList(){
        this.Test.log('老师-实验课',this.uid);
        const rm = (await Teacher.labcou(this.uid));
        this.Test.log('老师-实验课',rm);
        if(rm[1]['statusCode'] == '200'){
          if(rm[1].data == [] || rm[1].data == ''){
            this.Toast.show('无课程');
            this.labList = [];
            return;
          }
          this.labList = rm[1].data;
          //this.Toast.show('数据已加载');
        }
        else{
          this.Toast.show('网络连接失败');
        }
      },
      toSelectLab(item){
        uni.navigateTo({
          url: 'set_lab?obj=' + encodeURIComponent(JSON.stringify(item)),
          fail(e) {
            console.log(e);
          }
        });
      },
      toSelectSign(item){
        uni.navigateTo({
          url: 'set_sign?obj=' + encodeURIComponent(JSON.stringify(item)),
          fail(e) {
            console.log(e);
          }
        });
      }
    }
  }
</script>

<style>
</style>
